{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4e4ad9b2",
   "metadata": {},
   "source": [
    "-----------\n",
    "* 日期：2022-9-21\\week 5(周三）\n",
    "* 课程：python\n",
    "* 记录人：洪梦瑶\n",
    "* 平时20%+期中30%-40%+期末40-50%\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4848d5b5",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "* 1. 数值（number）\n",
    "* 2. 字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa96e133",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    "\n",
    "> 1. 对数值进行分类\n",
    ">> 1. 整数（int）\n",
    ">> 2. 浮点型（float）\n",
    ">> 3. 复数(complex)\n",
    "> 2. 数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "92622de6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整数\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1eb77c73",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0067d934",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a+b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6c6edcde",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d = 2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4b81e63c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.666666666666667"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 除法\n",
    "17/3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "58f4c20c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 除法取整\n",
    "17//3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b227eb32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 除法取不尽余数\n",
    "17%3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d35c9aa5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 乘法\n",
    "5*3+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "21af9189",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5的平方\n",
    "5**2 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bca75f05",
   "metadata": {},
   "source": [
    "## 字符串\n",
    "> 1. 定义\n",
    "> 2. 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e221de9",
   "metadata": {},
   "source": [
    "\\(在行尾时):续行符<br />\\\\ : 反斜杠符号<br />\\' ：单引号<br />\\\" ：双引号<br />\\a : 响铃<br />\\b : 退格(Backspace)<br />\\n : 换行<br />\\000 ：空<br />\\v ：纵向制表符<br />\\t ：横向制表符<br />\\r ：回车，将 \\r 后面的内容移到字符串开头，并逐一替换开头部分的字符，直至将 \\r 后面的内容完全替换完成\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "71a30899",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "19f66ccc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 18\n",
    "b = \"18\"\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "95aa869d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'doesn’t'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 关于单引号与双引号\n",
    "\"doesn’t\" # 双引号 包 单引号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "76c8bad4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'doesn’t'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案1\n",
    "\"doesn’t\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "42f25a77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2  \\ 后面的内容是“符号”，转义，\\ 自动消失\n",
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "403110a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *正则表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "47c5b216",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "# 作用：\n",
    "# 1.可以保持原数据的结构，包含符号，换行等\n",
    "# 2.可以用来做代码注释\n",
    "NFU_招投标_HTML = \"\"\"\n",
    "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
    "    </a>\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "c75885b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
      "    </a>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(NFU_招投标_HTML)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "8e365a31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "### 三个引号来代码注释\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)  # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5b57acb",
   "metadata": {},
   "source": [
    "## 2.1 字符串的运算法则\n",
    "> 1. 字符串的拼接<br />\n",
    "<font color=\"red\">2.字符串的有序性</font>\n",
    "<br /> (1) enumerate:枚举\n",
    "<br /> (2) in可以查询成员是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "c1006cd0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'helloworld'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"hello\" + \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "9a33fa3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n",
      "你好，Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text = \"你好，\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result = text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad120f64",
   "metadata": {},
   "source": [
    "* 取值\n",
    "> 1. 取单个值\n",
    "> 2. 切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "9f5ad500",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "b7b01599",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "b673b132",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "fc9b11d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "8800b56b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "ed9871d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5dd59e6",
   "metadata": {},
   "source": [
    "# <font color=\"red\">期中考试类似题目:</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "fe726309",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "存在 广州 这个文本\n"
     ]
    }
   ],
   "source": [
    "# 实践：请检查 广州是否在 地址 里面\n",
    "# 检查i是否是广，然后判断i下一个值是否是州\n",
    "# 方法：enumerate:枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value == \"广\":\n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "be7fade0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法：in 可以查询成员变量\n",
    "print(\"广州\" in 地址)\n",
    "print(\"Alex\" in 地址)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "75c7cca7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 回去课后学习[字符串方法]（https://docs.python.org/3/org/library/）\n",
    "## 1. 首字母变大写\n",
    "## 2. 检查字符出现的次数\n",
    "print(\"alex\".capitalize())\n",
    "地址.count(\"广州\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
